local hunhun = fk.CreateSkill{
  name = "rmt__hunhun",
  tags = { Skill.Lord , Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["rmt__hunhun"] = "惛惛",
  [":rmt__hunhun"] = "主公技，锁定技，游戏开始时，“谵妄”后添加吴势力角色数个空白项；当所有项首次均为人名后，这些角色各减少1点体力上限，你回复等量点体力。",
}

hunhun:addEffect(fk.GameStart, {
  anim_type = "support",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(hunhun.name) and player:hasSkill("rmt__zhanwang")
  end,
  on_use = function (self, event, target, player, data)
    local h = 0
    for _, p in ipairs(player.room.alive_players) do
      if p.kingdom == "wu" then
        h = h + 1
      end
    end
    for loop = 1, 30, 1 do --空白项冗余只能给这么多了
      if player:getMark("rmt__zhanwang_area"..loop) == 0 then
        player.room:setPlayerMark(player, "rmt__zhanwang_area"..loop, "Blank")
        h = h - 1
        if h == 0 then break end
      end
    end
  end
})

hunhun:addEffect(fk.AfterSkillEffect, {
  anim_type = "support",
  can_trigger = function (self, event, target, player, data)
    local canuse = true
    for loop = 1, 30, 1 do
      local mark = player:getMark("rmt__zhanwang_area"..loop)
      if mark ~= 0 then
        if mark == "CenterArea" or mark == "DrawPileTop" or mark == "CardInBoard" or mark == "Blank" then
          canuse = false
        end
      end
    end
    return data.skill:getSkeleton().name == "rmt__zhanwang" and canuse and player:usedSkillTimes(hunhun.name, Player.HistoryGame) <= 1
    and player:hasSkill(hunhun.name) and player:hasSkill("rmt__zhanwang")
  end,
  on_use = function (self, event, target, player, data)
    player:setSkillUseHistory(hunhun.name, 2, Player.HistoryGame) --中途获得主公技也可触发，在一次发动后均为人名的谵妄结算后触发，然后设置发动次数伪限定
    local list = {}
    for loop = 1, 30, 1 do
      local mark = player:getMark("rmt__zhanwang_area"..loop)
      if mark ~= 0 then
        if mark ~= "CenterArea" and mark ~= "DrawPileTop" and mark ~= "CardInBoard" and mark ~= "Blank" then
          if not player.room:getPlayerById(player:getMark("rmt__zhanwang_areatoplayer"..loop)).dead then
            table.insertIfNeed(list, player.room:getPlayerById(player:getMark("rmt__zhanwang_areatoplayer"..loop)))
          end
        end
      end
    end
    if #list > 0 then
      for _, p in ipairs(list) do
        if not p.dead then
          player.room:changeMaxHp(p, -1)
        end
      end
    end
    if not player.dead then
      player.room:recover({ who = player,  num = #list, skillName = hunhun.name })
    end
  end
})

return hunhun